***Import, translate to UTF8, save and append all candidate data files***

*1998
clear
cd ".../Brazil_candidates_replication/consulta_cand_1998/"

import delimited "consulta_cand_1998_AC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_AC.dta, replace
import delimited "consulta_cand_1998_AL.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_AL.dta, replace
import delimited "consulta_cand_1998_AM.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_AM.dta, replace
import delimited "consulta_cand_1998_AP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_AP.dta, replace
import delimited "consulta_cand_1998_BA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_BA.dta, replace
import delimited "consulta_cand_1998_CE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_CE.dta, replace
import delimited "consulta_cand_1998_DF.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_DF.dta, replace
import delimited "consulta_cand_1998_ES.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_ES.dta, replace
import delimited "consulta_cand_1998_GO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_GO.dta, replace
import delimited "consulta_cand_1998_MA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_MA.dta, replace
import delimited "consulta_cand_1998_MG.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_MG.dta, replace
import delimited "consulta_cand_1998_MS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_MS.dta, replace
import delimited "consulta_cand_1998_MT.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_MT.dta, replace
import delimited "consulta_cand_1998_PA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_PA.dta, replace
import delimited "consulta_cand_1998_PB.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_PB.dta, replace
import delimited "consulta_cand_1998_PE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_PE.dta, replace
import delimited "consulta_cand_1998_PI.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_PI.dta, replace
import delimited "consulta_cand_1998_PR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_PR.dta, replace
import delimited "consulta_cand_1998_RJ.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_RJ.dta, replace
import delimited "consulta_cand_1998_RN.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_RN.dta, replace
import delimited "consulta_cand_1998_RO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_RO.dta, replace
import delimited "consulta_cand_1998_RR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_RR.dta, replace
import delimited "consulta_cand_1998_RS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_RS.dta, replace
import delimited "consulta_cand_1998_SC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_SC.dta, replace
import delimited "consulta_cand_1998_SE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_SE.dta, replace
import delimited "consulta_cand_1998_SP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_SP.dta, replace
import delimited "consulta_cand_1998_TO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_1998_TO.dta, replace

use consulta_cand_1998_AC.dta
append using consulta_cand_1998_AL consulta_cand_1998_AM consulta_cand_1998_AP /*
*/ consulta_cand_1998_BA consulta_cand_1998_CE consulta_cand_1998_DF /*
*/ consulta_cand_1998_ES consulta_cand_1998_GO consulta_cand_1998_MA /*
*/ consulta_cand_1998_MG consulta_cand_1998_MS consulta_cand_1998_MT /*
*/ consulta_cand_1998_PA consulta_cand_1998_PB consulta_cand_1998_PE /*
*/ consulta_cand_1998_PI consulta_cand_1998_PR consulta_cand_1998_RJ /*
*/ consulta_cand_1998_RN consulta_cand_1998_RO consulta_cand_1998_RR /*
*/ consulta_cand_1998_RS consulta_cand_1998_SC consulta_cand_1998_SE /*
*/ consulta_cand_1998_SP consulta_cand_1998_TO, force

save ".../Brazil_candidates_replication/cand_1998_appended.dta", replace


*2000
clear
cd ".../Brazil_candidates_replication/consulta_cand_2000/"

import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_AC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_AC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_AL.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_AL.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_AM.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_AM.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_AP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_AP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_BA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_BA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_CE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_CE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_ES.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_ES.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_GO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_GO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_MA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_MA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_MG.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_MG.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_MS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_MS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_MT.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_MT.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_PA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_PA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_PB.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_PB.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_PE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_PE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_PI.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_PI.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_PR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_PR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_RJ.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_RJ.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_RN.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_RN.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_RO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_RO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_RR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_RR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_RS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_RS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_SC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_SC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_SE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_SE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_SP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_SP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2000/consulta_cand_2000_TO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2000_TO.dta, replace

use consulta_cand_2000_AC.dta
append using consulta_cand_2000_AL consulta_cand_2000_AM consulta_cand_2000_AP /*
*/ consulta_cand_2000_BA consulta_cand_2000_CE /*
*/ consulta_cand_2000_ES consulta_cand_2000_GO consulta_cand_2000_MA /*
*/ consulta_cand_2000_MG consulta_cand_2000_MS consulta_cand_2000_MT /*
*/ consulta_cand_2000_PA consulta_cand_2000_PB consulta_cand_2000_PE /*
*/ consulta_cand_2000_PI consulta_cand_2000_PR consulta_cand_2000_RJ /*
*/ consulta_cand_2000_RN consulta_cand_2000_RO consulta_cand_2000_RR /*
*/ consulta_cand_2000_RS consulta_cand_2000_SC consulta_cand_2000_SE /*
*/ consulta_cand_2000_SP consulta_cand_2000_TO, force

save ".../Brazil_candidates_replication/cand_2000_appended.dta", replace


*2002
clear
cd ".../Brazil_candidates_replication/consulta_cand_2002/"

import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_AC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_AC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_AL.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_AL.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_AM.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_AM.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_AP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_AP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_BA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_BA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_CE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_CE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_DF.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_DF.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_ES.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_ES.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_GO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_GO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_MA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_MA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_MG.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_MG.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_MS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_MS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_MT.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_MT.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_PA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_PA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_PB.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_PB.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_PE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_PE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_PI.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_PI.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_PR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_PR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_RJ.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_RJ.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_RN.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_RN.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_RO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_RO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_RR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_RR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_RS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_RS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_SC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_SC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_SE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_SE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_SP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_SP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2002/consulta_cand_2002_TO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2002_TO.dta, replace

use consulta_cand_2002_AC.dta
append using consulta_cand_2002_AL consulta_cand_2002_AM consulta_cand_2002_AP /*
*/ consulta_cand_2002_BA consulta_cand_2002_CE consulta_cand_2002_DF /*
*/ consulta_cand_2002_ES consulta_cand_2002_GO consulta_cand_2002_MA /*
*/ consulta_cand_2002_MG consulta_cand_2002_MS consulta_cand_2002_MT /*
*/ consulta_cand_2002_PA consulta_cand_2002_PB consulta_cand_2002_PE /*
*/ consulta_cand_2002_PI consulta_cand_2002_PR consulta_cand_2002_RJ /*
*/ consulta_cand_2002_RN consulta_cand_2002_RO consulta_cand_2002_RR /*
*/ consulta_cand_2002_RS consulta_cand_2002_SC consulta_cand_2002_SE /*
*/ consulta_cand_2002_SP consulta_cand_2002_TO, force
/* I use force here because v28 is string for some states and long for others.
I do not use this variable. */

save ".../Brazil_candidates_replication/cand_2002_appended.dta", replace


*2004
clear
cd ".../Brazil_candidates_replication/consulta_cand_2004/"

import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_AC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_AC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_AL.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_AL.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_AM.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_AM.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_AP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_AP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_BA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_BA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_CE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_CE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_ES.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_ES.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_GO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_GO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_MA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_MA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_MG.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_MG.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_MS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_MS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_MT.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_MT.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_PA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_PA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_PB.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_PB.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_PE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_PE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_PI.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_PI.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_PR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_PR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_RJ.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_RJ.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_RN.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_RN.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_RO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_RO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_RR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_RR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_RS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_RS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_SC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_SC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_SE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_SE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_SP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_SP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2004/consulta_cand_2004_TO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2004_TO.dta, replace

use consulta_cand_2004_AC.dta
append using consulta_cand_2004_AL consulta_cand_2004_AM consulta_cand_2004_AP /*
*/ consulta_cand_2004_BA consulta_cand_2004_CE /*
*/ consulta_cand_2004_ES consulta_cand_2004_GO consulta_cand_2004_MA /*
*/ consulta_cand_2004_MG consulta_cand_2004_MS consulta_cand_2004_MT /*
*/ consulta_cand_2004_PA consulta_cand_2004_PB consulta_cand_2004_PE /*
*/ consulta_cand_2004_PI consulta_cand_2004_PR consulta_cand_2004_RJ /*
*/ consulta_cand_2004_RN consulta_cand_2004_RO consulta_cand_2004_RR /*
*/ consulta_cand_2004_RS consulta_cand_2004_SC consulta_cand_2004_SE /*
*/ consulta_cand_2004_SP consulta_cand_2004_TO, force
/* I use force here because v27 is string for some states and long for others.
I do not use this variable. */

save ".../Brazil_candidates_replication/cand_2004_appended.dta", replace


*2006
clear
cd ".../Brazil_candidates_replication/consulta_cand_2006/"

import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_AC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_AC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_AL.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_AL.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_AM.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_AM.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_AP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_AP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_BA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_BA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_CE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_CE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_DF.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_DF.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_ES.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_ES.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_GO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_GO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_MA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_MA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_MG.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_MG.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_MS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_MS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_MT.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_MT.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_PA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_PA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_PB.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_PB.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_PE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_PE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_PI.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_PI.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_PR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_PR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_RJ.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_RJ.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_RN.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_RN.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_RO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_RO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_RR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_RR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_RS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_RS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_SC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_SC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_SE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_SE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_SP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_SP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2006/consulta_cand_2006_TO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2006_TO.dta, replace

use consulta_cand_2006_AC.dta
append using consulta_cand_2006_AL consulta_cand_2006_AM consulta_cand_2006_AP /*
*/ consulta_cand_2006_BA consulta_cand_2006_CE consulta_cand_2006_DF /*
*/ consulta_cand_2006_ES consulta_cand_2006_GO consulta_cand_2006_MA /*
*/ consulta_cand_2006_MG consulta_cand_2006_MS consulta_cand_2006_MT /*
*/ consulta_cand_2006_PA consulta_cand_2006_PB consulta_cand_2006_PE /*
*/ consulta_cand_2006_PI consulta_cand_2006_PR consulta_cand_2006_RJ /*
*/ consulta_cand_2006_RN consulta_cand_2006_RO consulta_cand_2006_RR /*
*/ consulta_cand_2006_RS consulta_cand_2006_SC consulta_cand_2006_SE /*
*/ consulta_cand_2006_SP consulta_cand_2006_TO

save ".../Brazil_candidates_replication/cand_2006_appended.dta", replace


*2008
clear
cd ".../Brazil_candidates_replication/consulta_cand_2008/"

import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_AC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_AC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_AL.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_AL.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_AM.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_AM.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_AP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_AP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_BA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_BA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_CE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_CE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_ES.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_ES.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_GO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_GO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_MA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_MA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_MG.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_MG.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_MS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_MS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_MT.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_MT.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_PA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_PA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_PB.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_PB.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_PE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_PE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_PI.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_PI.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_PR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_PR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_RJ.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_RJ.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_RN.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_RN.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_RO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_RO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_RR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_RR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_RS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_RS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_SC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_SC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_SE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_SE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_SP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_SP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2008/consulta_cand_2008_TO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2008_TO.dta, replace

* For SP and RO there are missings, which is why the variable is string
use consulta_cand_2008_SP.dta, clear
destring v14, force replace
save consulta_cand_2008_SP.dta, replace
use consulta_cand_2008_RO.dta, clear
destring v14, force replace
save consulta_cand_2008_RO.dta, replace

use consulta_cand_2008_AC.dta
append using consulta_cand_2008_AL consulta_cand_2008_AM consulta_cand_2008_AP /*
*/ consulta_cand_2008_BA consulta_cand_2008_CE /*
*/ consulta_cand_2008_ES consulta_cand_2008_GO consulta_cand_2008_MA /*
*/ consulta_cand_2008_MG consulta_cand_2008_MS consulta_cand_2008_MT /*
*/ consulta_cand_2008_PA consulta_cand_2008_PB consulta_cand_2008_PE /*
*/ consulta_cand_2008_PI consulta_cand_2008_PR consulta_cand_2008_RJ /*
*/ consulta_cand_2008_RN consulta_cand_2008_RO consulta_cand_2008_RR /*
*/ consulta_cand_2008_RS consulta_cand_2008_SC consulta_cand_2008_SE /*
*/ consulta_cand_2008_SP consulta_cand_2008_TO

save ".../Brazil_candidates_replication/cand_2008_appended.dta", replace


*2010
clear
cd ".../Brazil_candidates_replication/consulta_cand_2010/"

import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_AC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_AC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_AL.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_AL.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_AM.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_AM.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_AP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_AP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_BA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_BA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_CE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_CE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_DF.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_DF.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_ES.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_ES.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_GO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_GO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_MA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_MA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_MG.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_MG.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_MS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_MS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_MT.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_MT.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_PA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_PA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_PB.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_PB.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_PE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_PE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_PI.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_PI.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_PR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_PR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_RJ.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_RJ.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_RN.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_RN.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_RO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_RO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_RR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_RR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_RS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_RS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_SC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_SC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_SE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_SE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_SP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_SP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2010/consulta_cand_2010_TO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2010_TO.dta, replace

use consulta_cand_2010_AC.dta, clear
append using consulta_cand_2010_AL consulta_cand_2010_AM consulta_cand_2010_AP /*
*/ consulta_cand_2010_BA consulta_cand_2010_CE consulta_cand_2010_DF /*
*/ consulta_cand_2010_ES consulta_cand_2010_GO consulta_cand_2010_MA /*
*/ consulta_cand_2010_MG consulta_cand_2010_MS consulta_cand_2010_MT /*
*/ consulta_cand_2010_PA consulta_cand_2010_PB consulta_cand_2010_PE /*
*/ consulta_cand_2010_PI consulta_cand_2010_PR consulta_cand_2010_RJ /*
*/ consulta_cand_2010_RN consulta_cand_2010_RO consulta_cand_2010_RR /*
*/ consulta_cand_2010_RS consulta_cand_2010_SC consulta_cand_2010_SE /*
*/ consulta_cand_2010_SP consulta_cand_2010_TO

save ".../Brazil_candidates_replication/cand_2010_appended.dta", replace


*2012
clear
cd ".../Brazil_candidates_replication/consulta_cand_2012/"

import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_AC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_AC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_AL.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_AL.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_AM.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_AM.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_AP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_AP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_BA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_BA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_CE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_CE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_ES.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_ES.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_GO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_GO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_MA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_MA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_MG.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_MG.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_MS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_MS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_MT.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_MT.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_PA.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_PA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_PB.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_PB.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_PE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_PE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_PI.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_PI.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_PR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_PR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_RJ.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_RJ.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_RN.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_RN.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_RO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_RO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_RR.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_RR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_RS.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_RS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_SC.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_SC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_SE.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_SE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_SP.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_SP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2012/consulta_cand_2012_TO.txt", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2012_TO.dta, replace

use consulta_cand_2012_AC.dta
append using consulta_cand_2012_AL consulta_cand_2012_AM consulta_cand_2012_AP /*
*/ consulta_cand_2012_BA consulta_cand_2012_CE /*
*/ consulta_cand_2012_ES consulta_cand_2012_GO consulta_cand_2012_MA /*
*/ consulta_cand_2012_MG consulta_cand_2012_MS consulta_cand_2012_MT /*
*/ consulta_cand_2012_PA consulta_cand_2012_PB consulta_cand_2012_PE /*
*/ consulta_cand_2012_PI consulta_cand_2012_PR consulta_cand_2012_RJ /*
*/ consulta_cand_2012_RN consulta_cand_2012_RO consulta_cand_2012_RR /*
*/ consulta_cand_2012_RS consulta_cand_2012_SC consulta_cand_2012_SE /*
*/ consulta_cand_2012_SP consulta_cand_2012_TO

save ".../Brazil_candidates_replication/cand_2012_appended.dta", replace


*2014
clear
cd ".../Brazil_candidates_replication/consulta_cand_2014/"

*only AC is utf-8 from prior reformatting
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_AC.csv", delimiter(";") encoding(UTF-8) clear
save consulta_cand_2014_AC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_AL.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_AL.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_AM.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_AM.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_AP.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_AP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_BA.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_BA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_CE.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_CE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_DF.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_DF.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_ES.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_ES.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_GO.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_GO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_MA.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_MA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_MG.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_MG.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_MS.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_MS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_MT.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_MT.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_PA.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_PA.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_PB.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_PB.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_PE.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_PE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_PI.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_PI.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_PR.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_PR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_RJ.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_RJ.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_RN.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_RN.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_RO.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_RO.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_RR.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_RR.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_RS.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_RS.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_SC.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_SC.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_SE.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_SE.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_SP.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_SP.dta, replace
import delimited ".../Brazil_candidates_replication/consulta_cand_2014/consulta_cand_2014_TO.csv", delimiter(";") encoding(ISO-8859-1) clear
save consulta_cand_2014_TO.dta, replace

use consulta_cand_2014_AC.dta
append using consulta_cand_2014_AL consulta_cand_2014_AM consulta_cand_2014_AP /*
*/ consulta_cand_2014_BA consulta_cand_2014_CE consulta_cand_2014_DF /*
*/ consulta_cand_2014_ES consulta_cand_2014_GO consulta_cand_2014_MA /*
*/ consulta_cand_2014_MG consulta_cand_2014_MS consulta_cand_2014_MT /*
*/ consulta_cand_2014_PA consulta_cand_2014_PB consulta_cand_2014_PE /*
*/ consulta_cand_2014_PI consulta_cand_2014_PR consulta_cand_2014_RJ /*
*/ consulta_cand_2014_RN consulta_cand_2014_RO consulta_cand_2014_RR /*
*/ consulta_cand_2014_RS consulta_cand_2014_SC consulta_cand_2014_SE /*
*/ consulta_cand_2014_SP consulta_cand_2014_TO, force

save ".../Brazil_candidates_replication/cand_2014_appended.dta", replace


***2014 vote data

*Appending the candidate election data.
clear
cd ".../Brazil_candidates_replication/votacao_candidato_munzona_2014/"

use "votacao_candidato_munzona_2014_AC.dta", clear
append using "votacao_candidato_munzona_2014_AL.dta" /*
*/"votacao_candidato_munzona_2014_AM.dta" "votacao_candidato_munzona_2014_AP.dta"/*
*/"votacao_candidato_munzona_2014_BA.dta" "votacao_candidato_munzona_2014_BR.dta"/*
*/"votacao_candidato_munzona_2014_CE.dta" "votacao_candidato_munzona_2014_DF.dta"/*
*/"votacao_candidato_munzona_2014_ES.dta" "votacao_candidato_munzona_2014_GO.dta"/*
*/"votacao_candidato_munzona_2014_MA.dta" "votacao_candidato_munzona_2014_MG_new_KB.dta"/*
*/"votacao_candidato_munzona_2014_MS.dta" "votacao_candidato_munzona_2014_MT.dta"/*
*/"votacao_candidato_munzona_2014_PA.dta" "votacao_candidato_munzona_2014_PB.dta"/*
*/"votacao_candidato_munzona_2014_PE.dta" "votacao_candidato_munzona_2014_PI.dta"/*
*/"votacao_candidato_munzona_2014_PR.dta" "votacao_candidato_munzona_2014_RJ.dta"/*
*/"votacao_candidato_munzona_2014_RN.dta" "votacao_candidato_munzona_2014_RO.dta"/*
*/"votacao_candidato_munzona_2014_RR.dta" "votacao_candidato_munzona_2014_RS.dta"/*
*/"votacao_candidato_munzona_2014_SC.dta" "votacao_candidato_munzona_2014_SE.dta"/*
*/"votacao_candidato_munzona_2014_SP_new_KB.dta" "votacao_candidato_munzona_2014_TO.dta"

*Just keeping electoral results for deputados federais
keep if DESCRICAO_CARGO=="DEPUTADO FEDERAL"

*Renaming variables (CED abbreviation for candidate election data)
rename TOTAL_VOTOS votes_CED
rename SQ_CANDIDATO id_2014
rename SIGLA_UF state

*Keep relevant variables
keep votes_CED id_2014 state

*Aggregating data: Collapse data on zona and municipality level to state level
collapse (sum) votes_CED, by (id_2014 state)

save ".../Brazil_candidates_replication/vote_2014.dta", replace


*Append the party election data.
clear
cd ".../Brazil_candidates_replication/votacao_partido_munzona_2014/"

import delimited "votacao_partido_munzona_2014_AC.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_AC.dta, replace
import delimited "votacao_partido_munzona_2014_AL.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_AL.dta, replace
import delimited "votacao_partido_munzona_2014_AM.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_AM.dta, replace
import delimited "votacao_partido_munzona_2014_AP.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_AP.dta, replace
import delimited "votacao_partido_munzona_2014_BA.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_BA.dta, replace
import delimited "votacao_partido_munzona_2014_CE.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_CE.dta, replace
import delimited "votacao_partido_munzona_2014_DF.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_DF.dta, replace
import delimited "votacao_partido_munzona_2014_ES.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_ES.dta, replace
import delimited "votacao_partido_munzona_2014_GO.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_GO.dta, replace
import delimited "votacao_partido_munzona_2014_MA.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_MA.dta, replace
import delimited "votacao_partido_munzona_2014_MG.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_MG.dta, replace
import delimited "votacao_partido_munzona_2014_MS.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_MS.dta, replace
import delimited "votacao_partido_munzona_2014_MT.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_MT.dta, replace
import delimited "votacao_partido_munzona_2014_PA.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_PA.dta, replace
import delimited "votacao_partido_munzona_2014_PB.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_PB.dta, replace
import delimited "votacao_partido_munzona_2014_PE.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_PE.dta, replace
import delimited "votacao_partido_munzona_2014_PI.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_PI.dta, replace
import delimited "votacao_partido_munzona_2014_PR.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_PR.dta, replace
import delimited "votacao_partido_munzona_2014_RJ.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_RJ.dta, replace
import delimited "votacao_partido_munzona_2014_RN.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_RN.dta, replace
import delimited "votacao_partido_munzona_2014_RO.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_RO.dta, replace
import delimited "votacao_partido_munzona_2014_RR.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_RR.dta, replace
import delimited "votacao_partido_munzona_2014_RS.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_RS.dta, replace
import delimited "votacao_partido_munzona_2014_SC.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_SC.dta, replace
import delimited "votacao_partido_munzona_2014_SE.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_SE.dta, replace
import delimited "votacao_partido_munzona_2014_SP.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_SP.dta, replace
import delimited "votacao_partido_munzona_2014_TO.csv", delimiter(";") encoding(ISO-8859-1) clear
save party_2014_TO.dta, replace

use party_2014_AC.dta, clear
append using party_2014_AL party_2014_AM party_2014_AP /*
*/ party_2014_BA party_2014_CE party_2014_DF /*
*/ party_2014_ES party_2014_GO party_2014_MA /*
*/ party_2014_MG party_2014_MS party_2014_MT /*
*/ party_2014_PA party_2014_PB party_2014_PE /*
*/ party_2014_PI party_2014_PR party_2014_RJ /*
*/ party_2014_RN party_2014_RO party_2014_RR /*
*/ party_2014_RS party_2014_SC party_2014_SE /*
*/ party_2014_SP party_2014_TO, force

save ".../Brazil_candidates_replication/partyvote_2014_appended.dta", replace



***2014 campaign expenditure data
*Append
clear
cd ".../Brazil_candidates_replication/prestacao_final_2014/"

import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_AC.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_AC.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_AL.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_AL.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_AM.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_AM.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_AP.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_AP.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_BA.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_BA.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_CE.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_CE.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_DF.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_DF.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_ES.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_ES.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_GO.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_GO.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_MA.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_MA.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_MG.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_MG.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_MS.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_MS.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_MT.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_MT.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_PA.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_PA.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_PB.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_PB.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_PE.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_PE.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_PI.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_PI.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_PR.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_PR.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_RJ.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_RJ.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_RN.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_RN.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_RO.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_RO.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_RR.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_RR.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_RS.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_RS.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_SC.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_SC.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_SE.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_SE.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_SP.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_SP.dta, replace
import delimited ".../Brazil_candidates_replication/prestacao_final_2014/despesas_candidatos_2014_TO.txt", delimiter(";") encoding(ISO-8859-1) clear
save prestacao_final_2014_TO.dta, replace

use despesas_aggr_2014_AC.dta, clear
append using despesas_aggr_2014_AL despesas_aggr_2014_AM despesas_aggr_2014_AP /*
*/ despesas_aggr_2014_BA despesas_aggr_2014_CE despesas_aggr_2014_DF /*
*/ despesas_aggr_2014_ES despesas_aggr_2014_GO despesas_aggr_2014_MA /*
*/ despesas_aggr_2014_MG despesas_aggr_2014_MS despesas_aggr_2014_MT /*
*/ despesas_aggr_2014_PA despesas_aggr_2014_PB despesas_aggr_2014_PE /*
*/ despesas_aggr_2014_PI despesas_aggr_2014_PR despesas_aggr_2014_RJ /*
*/ despesas_aggr_2014_RN despesas_aggr_2014_RO despesas_aggr_2014_RR /*
*/ despesas_aggr_2014_RS despesas_aggr_2014_SC despesas_aggr_2014_SE /*
*/ despesas_aggr_2014_SP despesas_aggr_2014_TO, force



*Collapse first to reduce the size of the data
use despesas_final_2014_AC.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_AC.dta, replace
use despesas_final_2014_AL.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_AL.dta, replace
use despesas_final_2014_AM.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_AM.dta, replace
use despesas_final_2014_AP.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_AP.dta, replace
use despesas_final_2014_BA.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_BA.dta, replace
use despesas_final_2014_CE.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_CE.dta, replace
use despesas_final_2014_DF.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_DF.dta, replace
use despesas_final_2014_ES.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_ES.dta, replace
use despesas_final_2014_GO.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_GO.dta, replace
use despesas_final_2014_MA.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_MA.dta, replace
use despesas_final_2014_MG.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_MG.dta, replace
use despesas_final_2014_MS.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_MS.dta, replace
use despesas_final_2014_MT.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_MT.dta, replace
use despesas_final_2014_PA.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_PA.dta, replace
use despesas_final_2014_PB.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_PB.dta, replace
use despesas_final_2014_PE.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_PE.dta, replace
use despesas_final_2014_PI.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_PI.dta, replace
use despesas_final_2014_PR.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_PR.dta, replace
use despesas_final_2014_RJ.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_RJ.dta, replace
use despesas_final_2014_RN.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_RN.dta, replace
use despesas_final_2014_RO.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_RO.dta, replace
use despesas_final_2014_RR.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_RR.dta, replace
use despesas_final_2014_RS.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_RS.dta, replace
use despesas_final_2014_SC.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_SC.dta, replace
use despesas_final_2014_SE.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_SE.dta, replace
use despesas_final_2014_SP.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_SP.dta, replace
use despesas_final_2014_TO.dta, clear
keep if cargo=="Deputado Federal"
destring valordespesa, dpcomma replace force
collapse (first) uf (sum) valordespesa, by(sequencialcandidato)
save despesas_aggr_2014_TO.dta, replace

use despesas_aggr_2014_AC.dta, clear
append using despesas_aggr_2014_AL despesas_aggr_2014_AM despesas_aggr_2014_AP /*
*/ despesas_aggr_2014_BA despesas_aggr_2014_CE despesas_aggr_2014_DF /*
*/ despesas_aggr_2014_ES despesas_aggr_2014_GO despesas_aggr_2014_MA /*
*/ despesas_aggr_2014_MG despesas_aggr_2014_MS despesas_aggr_2014_MT /*
*/ despesas_aggr_2014_PA despesas_aggr_2014_PB despesas_aggr_2014_PE /*
*/ despesas_aggr_2014_PI despesas_aggr_2014_PR despesas_aggr_2014_RJ /*
*/ despesas_aggr_2014_RN despesas_aggr_2014_RO despesas_aggr_2014_RR /*
*/ despesas_aggr_2014_RS despesas_aggr_2014_SC despesas_aggr_2014_SE /*
*/ despesas_aggr_2014_SP despesas_aggr_2014_TO, force

*Prepare variables
rename uf state
rename sequencialcandidato id_2014
destring id_2014, replace
rename valordespesa camp_exp_CE

keep state id_2014 camp_exp_CE

save ".../Brazil_candidates_replication/despesas_2014_appended.dta", replace

*Continue with Candidate_campex_vote.do

